package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.Spring;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;

/**
 * 
 * This class pull out the flowers, vases and raw materials details for sending it to the form cobmoboxes
 * @author Gabi Revah
 * @author Aviad Almog
 * 
 */
public class MessageInventoryForm {

	private ConnectionToClient client ;
	private String[] str; 

/**
 * Constructor of this class
 * @param str
 * @param client
 */
	public MessageInventoryForm(String[] str, ConnectionToClient client) {
		this.client= client ;
		this.str= str; 
	
	}
	/**
	 * This method gets all the inventory info from the DB
	 * @param str1 - contain the customer ID
	 * @param str2 - contain the type of the order- order for sale / order for rent
	 * @param str3 - contain the number of the order
	 * @param str4 - contain the date of the order
	 * @throws SQLException
	 * @throws IOException
	 */
public void InventoryForm(String str1,String str2,String str3,String str4) throws SQLException, IOException{
		

		
		
		SQLConnection sc = new SQLConnection();
		
		java.sql.PreparedStatement fs = sc.getConnection().prepareStatement("SELECT Name, color, suppID FROM db.flowers;");
		ResultSet FlowerRes= fs.executeQuery();
		java.sql.PreparedStatement vs = sc.getConnection().prepareStatement("SELECT Name, color, suppID FROM db.vases;");
		ResultSet VasesRes= vs.executeQuery();
		java.sql.PreparedStatement rws = sc.getConnection().prepareStatement("SELECT Name, suppID FROM db.rawmaterial;");
		ResultSet RewInvRes= rws.executeQuery();
		
		Vector<Vector<String>> data = new Vector<Vector<String>>();
		Vector<String> temp = new Vector<String>();
		temp.add("InventoryForm");
		data.add(temp);
		Vector<String> rowso = new Vector<String>();
		Vector<String> rows1 = new Vector<String>();
		Vector<String> rows2 = new Vector<String>();
		while (FlowerRes.next())
		{
			rowso.add(FlowerRes.getString(1));
			rowso.add(FlowerRes.getString(2));
			rowso.add(FlowerRes.getString(3));
			
		}
		data.add(rowso);
		data.add(temp);
		while (VasesRes.next())
		{
			rows1.add(VasesRes.getString(1));
			rows1.add(VasesRes.getString(2));
			rows1.add(VasesRes.getString(3));
			
		}
		data.add(rows1);
		data.add(temp);
		while (RewInvRes.next())
		{
			rows2.add(RewInvRes.getString(1));
			rows2.add(RewInvRes.getString(2));
			
		}
		data.add(rows2);
		Vector<String> temp1 = new Vector<String>();
		temp1.add(str2);
		temp1.add(str1);
		temp1.add(str3);
		temp1.add(str4);
		data.add(temp1);
		client.sendToClient(data);
		
	}
}
